﻿Imports System.Data.Linq
Imports System.Linq

Public Class CRoleController
    Dim objDataContext As New TanNamChinhDataContext
    Public Function SelectAllRecord() As Table(Of tblRole)
        Try
            Return objDataContext.tblRoles
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Function SelectRecordByID(ByVal _id As Integer) As tblRole
        Try
            Return (From r In objDataContext.tblRoles
                    Where r.ID_Role = _id
                    Select r).Single

        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Sub UpdateRecord(ByVal LocalTable As tblRole)
        Try
            objDataContext.tblRoles.Attach(LocalTable, True)
            objDataContext.Refresh(RefreshMode.KeepCurrentValues, LocalTable)
            objDataContext.SubmitChanges(ConflictMode.ContinueOnConflict)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Public Sub UpdateRecordWithoutAttach(ByVal LocalTable As tblRole)
        Try
            objDataContext.Refresh(RefreshMode.KeepCurrentValues, LocalTable)
            objDataContext.SubmitChanges(ConflictMode.ContinueOnConflict)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Sub DeleteRecord(ByVal _id As Integer)
        Try
            Dim objUser = (From r In objDataContext.tblRoles
                          Where r.ID_Role = _id).Single
            objDataContext.tblRoles.DeleteOnSubmit(objUser)
            objDataContext.SubmitChanges()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Public Sub New()
        objDataContext = New TanNamChinhDataContext
    End Sub
    Public Sub New(ByVal _obj As TanNamChinhDataContext)
        objDataContext = _obj
    End Sub
End Class
